function totalFuel = TotalFuelConsumption(x)

%REDACTED LOAD OF MAERSK MODULE;%

global n A B earliestArrival undercoverPenalty listing hitViolation
global ETAViolation pointIdentifiers ETA latestArrival undercoverPenalty2
global additionalOffTime

pointIdentifiers = zeros(n+2, 4);
pointIdentifiers(1, 1) = A(1);
pointIdentifiers(1, 2) = A(2);
pointIdentifiers(1, 3) = 0;
pointIdentifiers(1, 4) = 0;
for i = 2:n+1
    pointIdentifiers(i, 1) = x((i-2)*3 + 1);
    pointIdentifiers(i, 2) = x((i-2)*3 + 2);
    pointIdentifiers(i, 3) = x((i-2)*3 + 3);
    pointIdentifiers(i, 4) = pointIdentifiers(i-1, 4) + ...
        60*distance(pointIdentifiers(i-1, 1), pointIdentifiers(i-1, 2),...
        pointIdentifiers(i, 1), pointIdentifiers(i, 2))/...
        pointIdentifiers(i, 3);
end
pointIdentifiers(n+2, 1) = B(1);
pointIdentifiers(n+2, 2) = B(2);
pointIdentifiers(n+2, 3) = x(n*3+1);
pointIdentifiers(n+2, 4) = pointIdentifiers(n+1, 4) + ...
    60*distance(pointIdentifiers(n+1, 1), pointIdentifiers(n+1, 2),...
    pointIdentifiers(n+2, 1), pointIdentifiers(n+2, 2))/...
    pointIdentifiers(n+2, 3);

ETA = pointIdentifiers(n+2, 4);
listing = ceil(pointIdentifiers(:, 4));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%CREATES THE WAY POINT 3D MATRIX USED IN COMPLEX CALCULATIONS
WayPoint3D()

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%DETERMINES THE TOTAL FUEL BY CALLS TO SIMPLE OR COMPLEX
if ETA > latestArrival + additionalOffTime || ETA < ...
        earliestArrival - additionalOffTime
    totalFuel = SimpleFuelCalculations()/1000;
else
    totalFuel = ComplexFuelCalculation()/1000;
end

%GIVES PENALTIES TO FULE COMSUMPTION
overETA = ETA - B(3);
if overETA > 0
    totalFuel = totalFuel + overETA*undercoverPenalty*2;
end
if hitViolation > 0
    totalFuel = totalFuel + hitViolation*undercoverPenalty2*2;
end


    

    